package fr.esisar.cs420.swt;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

import fr.esisar.cs420.traitement.Album;


public class AccueilClient extends Composite {

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public AccueilClient(final Composite parent, int style) {
		super(parent, style);
		
		Group grpVisualiser = new Group(this, SWT.NONE);
		grpVisualiser.setText("Visualiser");
		grpVisualiser.setBounds(10, 10, 267, 253);
		
		Button btnVoirLesLivres = new Button(grpVisualiser, SWT.NONE);
		btnVoirLesLivres.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				try {
					Display display = Display.getDefault();
					VisualiseLivre shell = new VisualiseLivre(display,1);
					shell.open();
					shell.layout();
					while (!shell.isDisposed()) {
						if (!display.readAndDispatch()) {
							display.sleep();
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
			}
				
				Album.removeAlbum();
				
			}
		});
		btnVoirLesLivres.setBounds(53, 100, 167, 25);
		btnVoirLesLivres.setText("Voir les Livres publics");
		
		Button button_1 = new Button(grpVisualiser, SWT.NONE);
		button_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				try {
					Display display = Display.getDefault();
					VisualiseAlbum shell = new VisualiseAlbum(display,1);
					shell.open();
					shell.layout();
					while (!shell.isDisposed()) {
						if (!display.readAndDispatch()) {
							display.sleep();
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
			}
				
				Album.removeAlbum();
				
			}
		});
		button_1.setText("Voir les Albums publics");
		button_1.setBounds(53, 62, 167, 25);
		
		Label lblVoirLesAlbums = new Label(grpVisualiser, SWT.NONE);
		lblVoirLesAlbums.setBounds(53, 29, 233, 15);
		lblVoirLesAlbums.setText("Voir les albums ou livre publics");
		
		Label lblVoirMesAlbums = new Label(grpVisualiser, SWT.NONE);
		lblVoirMesAlbums.setText("Voir mes albums ou livre ");
		lblVoirMesAlbums.setBounds(68, 142, 233, 15);
		
		Button btnVoirMesAlbums = new Button(grpVisualiser, SWT.NONE);
		btnVoirMesAlbums.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				try {
					Display display = Display.getDefault();
					VisualiseAlbum shell = new VisualiseAlbum(display,0);
					shell.open();
					shell.layout();
					while (!shell.isDisposed()) {
						if (!display.readAndDispatch()) {
							display.sleep();
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
			}
				
				Album.removeAlbum();
				
			}
		});
		btnVoirMesAlbums.setText("Voir mes Albums ");
		btnVoirMesAlbums.setBounds(53, 173, 167, 25);
		
		Button btnVoirMesLivres = new Button(grpVisualiser, SWT.NONE);
		btnVoirMesLivres.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				try {
					Display display = Display.getDefault();
					VisualiseLivre shell = new VisualiseLivre(display,0);
					shell.open();
					shell.layout();
					while (!shell.isDisposed()) {
						if (!display.readAndDispatch()) {
							display.sleep();
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
			}
				
				Album.removeAlbum();
				
			}
		});
		btnVoirMesLivres.setText("Voir mes Livres ");
		btnVoirMesLivres.setBounds(53, 214, 167, 25);
		
		Group grpGrer = new Group(this, SWT.NONE);
		grpGrer.setText("Gérer\r\n");
		grpGrer.setBounds(299, 10, 334, 350);
		
		Group grpMonCompte = new Group(grpGrer, SWT.NONE);
		grpMonCompte.setText("Mon compte\r\n");
		grpMonCompte.setBounds(10, 32, 314, 82);
		
		Button btnGrerMonCompte = new Button(grpMonCompte, SWT.NONE);
		btnGrerMonCompte.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				
				try {
					Display display = Display.getDefault();
					GestionCompte shell = new GestionCompte(display);
					shell.open();
					shell.layout();
					while (!shell.isDisposed()) {
						if (!display.readAndDispatch()) {
							display.sleep();
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
				}
				
			}
		});
		btnGrerMonCompte.setBounds(179, 47, 125, 25);
		btnGrerMonCompte.setText("Gestion de compte\r\n");
		
		Label lblBesoinDeChanger = new Label(grpMonCompte, SWT.NONE);
		lblBesoinDeChanger.setBounds(10, 21, 206, 15);
		lblBesoinDeChanger.setText("Besoin de changer vos informations ?\r\n");
		
		Button btnSeDconnecter = new Button(grpMonCompte, SWT.NONE);
		btnSeDconnecter.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				parent.dispose();
				
				try {
					Display display = Display.getDefault();
					InterfaceUtilisateur shell = new InterfaceUtilisateur(display);
					shell.open();
					shell.layout();
					while (!shell.isDisposed()) {
						if (!display.readAndDispatch()) {
							display.sleep();
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
			}
				
				
			}
		});
		btnSeDconnecter.setBounds(10, 47, 125, 25);
		btnSeDconnecter.setText("Se déconnecter");
		
		Group grpMesdAlbumslivres = new Group(grpGrer, SWT.NONE);
		grpMesdAlbumslivres.setText("Mes albums/livres");
		grpMesdAlbumslivres.setBounds(10, 120, 314, 103);
		
		Button btnGestion = new Button(grpMesdAlbumslivres, SWT.NONE);
		btnGestion.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				try {
					Display display = Display.getDefault();
					GestionAlbum shell = new GestionAlbum(display);
					shell.open();
					shell.layout();
					while (!shell.isDisposed()) {
						if (!display.readAndDispatch()) {
							display.sleep();
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
				}
				
				Album.removeAlbum();
				
			}
		});
		btnGestion.setBounds(171, 68, 133, 25);
		btnGestion.setText("Gérer mes albums\r\n");
		
		Label lblOutilsDeGestion = new Label(grpMesdAlbumslivres, SWT.NONE);
		lblOutilsDeGestion.setBounds(22, 33, 186, 15);
		lblOutilsDeGestion.setText("Outils de gestion d'albums/livres");
		
		Button btnGrerMesLivres = new Button(grpMesdAlbumslivres, SWT.NONE);
		btnGrerMesLivres.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				try {
					Display display = Display.getDefault();
					GestionLivre shell = new GestionLivre(display);
					shell.open();
					shell.layout();
					while (!shell.isDisposed()) {
						if (!display.readAndDispatch()) {
							display.sleep();
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
				}
				
				Album.removeAlbum();
				
			}
		});
		btnGrerMesLivres.setText("Gérer mes livres\r\n\r\n");
		btnGrerMesLivres.setBounds(32, 68, 133, 25);
		
		Group grpMesCommandes = new Group(grpGrer, SWT.NONE);
		grpMesCommandes.setText("Mes commandes");
		grpMesCommandes.setBounds(10, 229, 314, 103);
		
		Button btnNewButton = new Button(grpMesCommandes, SWT.NONE);
		btnNewButton.setBounds(150, 68, 156, 25);
		btnNewButton.setText("Gestion de mes commandes");
		
		Label lblOutilsDeGestion_1 = new Label(grpMesCommandes, SWT.NONE);
      
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				try {
					Display display = Display.getDefault();
					GestionCommandes shell = new GestionCommandes(display);
					shell.open();
					shell.layout();
					while (!shell.isDisposed()) {
						if (!display.readAndDispatch()) {
							display.sleep();
						}
					}
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		lblOutilsDeGestion_1.setBounds(20, 27, 180, 15);
		lblOutilsDeGestion_1.setText("Outils de gestion de commandes");

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
